#include<bits/stdc++.h>
using namespace std;
#define int long long


unordered_map<string, string> mp;

void init() {
	for (auto &i : mp) {
		i.second = i.first;
	}
}


string find(string s) {
	if (mp[s] != s)
		mp[s] = find(mp[s]);
	return mp[s];
}


void merge(string s, string t) {
	s = find(s);
	t = find(t);

	if (s != t) {
		mp[s] = mp[t];
	}
}


signed main() {

	int n, m;
	cin >> n >> m;

	while (n--) {
		string s;
		cin >> s;
		mp[s] = s;
	}

	while (m--) {
		string s, t;
		cin >> s >> t;
		merge(s, t);
	}

	int k;
	cin >> k;
	while (k--) {
		string s, t;
		cin >> s >> t;
		if (find(s) == find(t))
			cout << "Yes.";
		else
			cout << "No.";
		cout << endl;
	}

	return 0;
}
